// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PATIENT_INFO_EHC_E01 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("18 PID",18)]
  	    [HL7Field(HL7Version.v26, 18, HL7Repeat.False, HL7Required.True,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("19 PV1",19)]
  	    [HL7Field(HL7Version.v26, 19, HL7Repeat.False, HL7Required.False,"PV1")]
	    public PV1 PV1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("20 PV2",20)]
  	    [HL7Field(HL7Version.v26, 20, HL7Repeat.False, HL7Required.False,"PV2")]
	    public PV2 PV2 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 ACC",21)]
  	    [HL7Field(HL7Version.v26, 21, HL7Repeat.True, HL7Required.False,"ACC")]
	    public ACC[] ACC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("22 INSURANCE",22)]
  	    [HL7Field(HL7Version.v26, 22, HL7Repeat.True, HL7Required.True,"INSURANCE_EHC_E01")]
	    public INSURANCE_EHC_E01[] INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("26 DIAGNOSIS",26)]
  	    [HL7Field(HL7Version.v26, 26, HL7Repeat.True, HL7Required.False,"DIAGNOSIS_EHC_E01")]
	    public DIAGNOSIS_EHC_E01[] DIAGNOSIS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("30 OBX",30)]
  	    [HL7Field(HL7Version.v26, 30, HL7Repeat.True, HL7Required.False,"OBX")]
	    public OBX[] OBX {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			PV1 = PopSegmentParseAndCheckRequired<PV1>(availableData, options, "PV1");
			PV2 = PopSegmentParseAndCheckRequired<PV2>(availableData, options, "PV2");
			ACC = PopSegmentParseAndCheckRequiredArray<ACC>(availableData, options, "ACC");
			INSURANCE = ProcessGroupArray<INSURANCE_EHC_E01>(availableData, options, "INSURANCE");
			DIAGNOSIS = ProcessGroupArray<DIAGNOSIS_EHC_E01>(availableData, options, "DIAGNOSIS");
			OBX = PopSegmentParseAndCheckRequiredArray<OBX>(availableData, options, "OBX");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			bool isPV1 = availableData.StartsWith("PV1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PV1", options.Version) || isPV1) {
				return isPV1;
			}
			bool isPV2 = availableData.StartsWith("PV2", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PV2", options.Version) || isPV2) {
				return isPV2;
			}
			bool isACC = availableData.StartsWith("ACC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ACC", options.Version) || isACC) {
				return isACC;
			}
			INSURANCE_EHC_E01 testINSURANCE_EHC_E01 = new INSURANCE_EHC_E01();
			bool grpCCINSURANCE_EHC_E01 = (testINSURANCE_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("INSURANCE", options.Version) || grpCCINSURANCE_EHC_E01) {
				return grpCCINSURANCE_EHC_E01;
			}
			DIAGNOSIS_EHC_E01 testDIAGNOSIS_EHC_E01 = new DIAGNOSIS_EHC_E01();
			bool grpCCDIAGNOSIS_EHC_E01 = (testDIAGNOSIS_EHC_E01.CanConsume(availableData, options));
			if (IsRequired("DIAGNOSIS", options.Version) || grpCCDIAGNOSIS_EHC_E01) {
				return grpCCDIAGNOSIS_EHC_E01;
			}
			bool isOBX = availableData.StartsWith("OBX", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBX", options.Version) || isOBX) {
				return isOBX;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PATIENT_INFO";
			}
        }

        static PATIENT_INFO_EHC_E01() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PATIENT_INFO_EHC_E01));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PV1 != null) {
			string segmentValue = PV1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PV2 != null) {
			string segmentValue = PV2.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ACC != null && ACC.Length > 0) {
			for (int i = 0; i < ACC.Length; i++) {
				string segmentValue = ACC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (INSURANCE != null && INSURANCE.Length > 0) {
			for (int i = 0; i < INSURANCE.Length; i++) {
				string segmentValue = INSURANCE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (DIAGNOSIS != null && DIAGNOSIS.Length > 0) {
			for (int i = 0; i < DIAGNOSIS.Length; i++) {
				string segmentValue = DIAGNOSIS[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBX != null && OBX.Length > 0) {
			for (int i = 0; i < OBX.Length; i++) {
				string segmentValue = OBX[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

